package com.sgb.link.entity;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import com.swgk.core.BaseAppHelper;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.util.SystemUtil;

/**
 * @author: 王彬臣
 * @date: 2021/12/29
 * @Description: 物流埋点统计实体
 */
public class LogisticsFlowLog {
    private String appIndex;
    /**
     * brandName :
     * deviceModel :
     * os :
     * osVersion :
     */

    private HowBean how=new HowBean();
    /**
     * elementName :
     * elementType :
     * pageName :
     */

    private WhatBean what;

    /**
     * city : 0
     * province :
     */

    private WhereBean where=new WhereBean();

    public String getAppIndex() {
        return appIndex;
    }

    public void setAppIndex(String appIndex) {
        this.appIndex = appIndex;
    }

    public LogisticsFlowLog(String pageName, String element_name, String element_type) {
        appIndex=getPackageName(BaseAppHelper.get().getInstance());
        what=new WhatBean();
        what.setPageName(pageName);
        what.setElementName(element_name);
        what.setElementType(element_type);
    }

    public HowBean getHow() {
        return how;
    }

    public void setHow(HowBean how) {
        this.how = how;
    }

    public WhatBean getWhat() {
        return what;
    }

    public void setWhat(WhatBean what) {
        this.what = what;
    }



    public WhereBean getWhere() {
        return where;
    }

    public void setWhere(WhereBean where) {
        this.where = where;
    }




    public static class HowBean {
        private String brandName;
        private String deviceModel;
        private String os;
        private String osVersion;

        public HowBean() {
            os="Android";
            osVersion = "Android " + SystemUtil.getSystemVersion(); // 系统版本
            deviceModel=SystemUtil.getDeviceBrand();//设备型号
            brandName=SystemUtil.getSystemModel();//厂商
        }

        public String getBrandName() {
            return brandName;
        }

        public void setBrandName(String brandName) {
            this.brandName = brandName;
        }

        public String getDeviceModel() {
            return deviceModel;
        }

        public void setDeviceModel(String deviceModel) {
            this.deviceModel = deviceModel;
        }

        public String getOs() {
            return os;
        }

        public void setOs(String os) {
            this.os = os;
        }

        public String getOsVersion() {
            return osVersion;
        }

        public void setOsVersion(String osVersion) {
            this.osVersion = osVersion;
        }
    }

    public static class WhatBean {
        private String elementName;
        private String elementType;
        private String pageName;

        public String getElementName() {
            return elementName;
        }

        public void setElementName(String elementName) {
            this.elementName = elementName;
        }

        public String getElementType() {
            return elementType;
        }

        public void setElementType(String elementType) {
            this.elementType = elementType;
        }

        public String getPageName() {
            return pageName;
        }

        public void setPageName(String pageName) {
            this.pageName = pageName;
        }
    }



    public static class WhereBean {
        private String city;
        private String province;

        public WhereBean() {
            this.province=SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.Province, "");
            this.city=SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.City, "");
            if (TextUtils.isEmpty(province)) {
                province="新疆维吾尔自治区";
            }
        }

        public String getCity() {
            return city;
        }

        public void setCity(String city) {
            this.city = city;
        }

        public String getProvince() {
            return province;
        }

        public void setProvince(String province) {
            this.province = province;
        }
    }

    /**
     * 获取本地软件版本名称
     */
    public String getPackageName(Context context) {
        String packageName = "";
        try {
            PackageInfo packageInfo = context.getApplicationContext()
                    .getPackageManager()
                    .getPackageInfo(context.getPackageName(), 0);
            packageName = packageInfo.packageName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return packageName;
    }
}
